import {
	RouterMount,
	createRouter
} from 'uni-simple-router';

const whiteList = ['/pages/welcome/index']

const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,
	routes: [...ROUTES]
});
//全局路由前置守卫
router.beforeEach((to, from, next) => {
	// 是否登陆
	if (uni.getStorageSync("miuUserInfo")) {
		// 如果你到登陆页
		if (to.path == '/pages/welcome/index') {
			next("pages/home/index")
		} else {
			next();
		}
	} else {
		if (whiteList.indexOf(to.path) !== -1) {
			// 在免登录白名单，直接进入
			next()
		} else {
			// 否则全部重定向到登录页
			next('/pages/welcome/index')
		}
	}
});
// 全局路由后置守卫
router.afterEach((to, from) => {

})

export {
	router,
	RouterMount
}